<template>
  <div class="page">
    <div class="searchline" style="margin: 20px 0">
      <el-input
        placeholder="职位名称"
        v-model="search.Job_name"
        size="medium"
        style="width: 200px; margin-left: 12px"
      ></el-input>
      <el-input
        placeholder="公司名称"
        v-model="search.company_name"
        size="medium"
        style="width: 200px; margin-left: 12px"
      ></el-input>
      <el-select
        placeholder="状态"
        size="medium"
        v-model="search.status"
        style="width: 200px; margin-left: 12px"
      >
        <el-option label="已回复" :value="1"> </el-option>
        <el-option label="未回复" :value="0"> </el-option>
      </el-select>
      <el-button
        style="margin-left: 12px"
        size="medium"
        type="primary"
        @click="searchFromList(search)"
        >筛选</el-button
      >
      <el-button size="medium" type="info" @click="reSet()">重置</el-button>
    </div>
    <el-table
      header-row-class-name="tableHeader"
      :data="tableData"
      border
      style="width: 98%; margin-left: 12px"
    >
      <el-table-column prop="Job_name" label="职位" width="180px"> </el-table-column>
      <el-table-column prop="company_name" label="企业名称" width="180px"> </el-table-column>
      <el-table-column prop="reply" label="企业回复"> </el-table-column>
      <el-table-column prop="status" label="投递状态" width="100px">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0" style="color: red">未回复</span>
          <span v-else style="color: rgb(65, 151, 46)">已回复</span>
        </template>
      </el-table-column>
      <el-table-column prop="created_date" label="投递日期" width="150px">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { allRecord } from "@/api/record";
import { localData } from "@/util/local";
import { dateFormat } from "@/util/common";

export default {
  data() {
    return {
      tableData: [],
      initTableData: [],
      userInfo: {},
      search: {
        Job_name: "",
        company_name: "",
        status: "",
      },
    };
  },
  created() {
    this.userInfo = localData("get", "userinfo");
  },
  mounted() {
    this.getMyRecord();
  },
  methods: {
    getMyRecord() {
      const param = {
        user_id: this.userInfo.id,
      };
      allRecord(param).then((res) => {
        this.initTableData = res.data.Records.map((item) => {
          item.created_date = dateFormat(
            "YYYY-mm-dd HH:MM",
            new Date(item.created_date)
          );
          return item;
        });
        this.tableData = this.initTableData;
      });
    },
    searchFromList(search) {
      const { Job_name, company_name, status } = search;
      this.tableData = this.initTableData.filter((item) => {
        return item.Job_name.toString().indexOf(Job_name.toString()) !== -1 && item.company_name.toString().indexOf(company_name.toString()) !== -1 && item.status.toString().indexOf(status.toString()||'') !== -1
      });
    },
    reSet() {
      this.search = {
        name: "",
        company_name: "",
      };
      this.tableData = this.initTableData;
    },
  },
};
</script>

<style>
.tableHeader {
  color: rgb(65, 151, 46) !important;
}
</style>